﻿using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Example.Objects1;
using Example.Objects2;

namespace Example.Mappers.Tests
{
    [TestClass]
    public class CustomerMapperTest
    {
        [TestMethod]
        public void MapTo_Customer2From_Customer1_ReturnsEquivalent()
        {
            var srcCustomer = CreateCustomer1();

            var dstCustomer = srcCustomer.ToCustomer2();

            CustomAssert.AreEquivalent(srcCustomer, dstCustomer);
        }

        [TestMethod]
        public void MapFrom_Customer2ToNewCustomer1_InjectsEquivalent()
        {
            var srcCustomer = CreateCustomer2();

            var dstCustomer = new Customer1().From(srcCustomer);

            CustomAssert.AreEquivalent(srcCustomer, dstCustomer);
        }

        [TestMethod]
        [ExpectedException(typeof(NullReferenceException))]
        public void MapFrom_Customer2ToNullCustomer1_ThrowsException()
        {
            var srcCustomer = CreateCustomer2();
            
            Customer1 dstCustomer = null;
            dstCustomer = dstCustomer.From(srcCustomer);
        }

        public static Customer1 CreateCustomer1()
        {
            return new Customer1()
            {
                Id = 1,
                Status = Status1.Active,
                Role = new Objects1.Person()
                {
                    Gender = Gender1.Male,
                    FirstName = "Albert",
                    LastName = "Dupont",
                    BirthDate = Convert.ToDateTime("1987-10-31T00:00:00")
                },
                Address = new Address1()
                {
                    Country = new KeyValuePair<int, string>(33, "France"),
                    City = "Paris",
                    Street = new Street1()
                    {
                        Name = "rue Dauphine",
                        Number = "7"
                    }
                },
                WebAccounts = new List<WebAccount1>()
                {
                    new WebAccount1() { UserName = "albert.dupont", EmailAddress = "albert@dupont.fr" },
                    new WebAccount1() { UserName = "adupont", EmailAddress = "adupont@hotmail.fr" }
                }
            };
        }
        public static Customer2 CreateCustomer2()
        {
            return new Customer2()
            {
                Status = Status2.NotActive,
                Role = new Objects2.Company()
                {
                    Name = "MachinChose",
                    Number = 88,
                    Employees = new Dictionary<string, Objects2.Employee2>()
                    {
                        { "MC0001", new Employee2 {
                            Person = new Objects2.Person() { FirstName = "Jean", LastName = "Martin" },
                            Address = new Address2 { City = "Versailles", Street = new Street2 { Name = "avenue de Paris", Number = "3 bis" } },
                            WebAccount = new WebAccount2 { UserName = "jma", EmailAddress = "jma@machinchose.com" } } },
                        { "MC0002", new Employee2 {
                            Person = new Objects2.Person() { FirstName = "Philippe", LastName = "Durand" },
                            Address = new Address2 { City = "Vélizy", Street = new Street2 { Name = "rue Nieuport", Number = "45" } },
                            WebAccount = new WebAccount2 { UserName = "pdu", EmailAddress = "pdu@machinchose.com" } } }
                    }
                },
                Address = new Address2()
                {
                    Country = new KeyValuePair<CountryCode, string>(CountryCode.France, "France"),
                    City = "Versailles",
                    Street = new Street2()
                    {
                        Name = "avenue des États-Unis",
                        Number = "25bis"
                    }
                }
            };
        }
    }
}
